package com.cn.ccp.action.classschedule.user;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

import org.apache.log4j.Logger;

import com.cn.ccp.action.BaseAction;
import com.cn.ccp.bean.ClassScheduleDetailBean;
import com.cn.ccp.bean.ClassScheduleSettingsBean;
import com.cn.ccp.bean.TermSettingBean;
import com.cn.ccp.util.CCPContants;
import com.cn.ccp.util.Contants;
import com.cn.ccp.util.MsgConstants;

/**
 * 老师课程表
 * 只做显示
 * @author renyongchengO
 *O
 */
public class ClassScheduleDetailForTeacherAction extends BaseAction{
	private Logger log = Logger.getLogger(ClassScheduleDetailForTeacherAction.class);
	private String weekSchedule;//一周课程表
	private String daySchedule;//当天课程表
	
    public ClassScheduleDetailForTeacherAction(){
    	initSchedule(CCPContants.getCurrUserId());
    }
    	 
	private void initSchedule(String userId){
		Calendar cur = Calendar.getInstance();
		int dayForWeek = 1;
		if(cur.get(Calendar.DAY_OF_WEEK) == 1){  
			 dayForWeek = 7;  
		 }else{  
			 dayForWeek = cur.get(Calendar.DAY_OF_WEEK) - 1;  
		 }  
		int curYear = cur.get(Calendar.YEAR);
		List termSetList =  getTermSettingService().queryTerymByYear(curYear) ;
		if(termSetList == null){
			log.warn("Has been not setting class schudule..");
			return;
		}
		int count = termSetList.size();
		TermSettingBean termSettingBean ,curTermSettingBean = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		for(int i =0; i<count; i++){
			termSettingBean = (TermSettingBean)termSetList.get(i);
			Calendar cal = Calendar.getInstance();
			try {
				cal.setTime(sdf.parse(termSettingBean.getFirstWeekStart()));
			} catch (ParseException e) {
				log.error("format data failed : ", e);
			}
			log.info(termSettingBean);
			int value = cal.compareTo(cur) ;
			log.info("------value = "+value);
			if(value == -1)//cal 比 cur 早
				curTermSettingBean = termSettingBean;
			 
		}
		
		if(curTermSettingBean == null){
			log.warn("Has been not setting class schudule..");
			initNoSetting();
			return ;
		}
		
		List<ClassScheduleSettingsBean> allSet = getScheduleSettingService().pageQuery(0,20);
		int allCourse = allSet.size();//每天上课总节数
		int moningNum = 0,noonNum = 0,afterNoonNum = 0,nightNum = 0;//每天早上、上午、下午和晚上的课程节数
		for(ClassScheduleSettingsBean bean:allSet){
			if(bean.getClassScheduleType().equalsIgnoreCase(String.valueOf(Contants.SCHEDULE_TYPE_MORNING) ))
				moningNum++;
			else if(bean.getClassScheduleType().equalsIgnoreCase(String.valueOf(Contants.SCHEDULE_TYPE_FORENOON) ))
				noonNum++;
			else if(bean.getClassScheduleType().equalsIgnoreCase(String.valueOf(Contants.SCHEDULE_TYPE_AFTERNOON) ))
				afterNoonNum++;
			else if(bean.getClassScheduleType().equalsIgnoreCase(String.valueOf(Contants.SCHEDULE_TYPE_NIGHT) ))
				nightNum++;
		}
		
		String[][] week = new String[allCourse][7];
		log.info(userId+":"+curTermSettingBean.getId());
		List<ClassScheduleDetailBean> allList = getClassScheduleDetailService().pageQueryForTeacher(userId,curTermSettingBean.getId());//返回系统课程表
    	count = allList.size();
    	log.info("=============:count = "+count);
//    	for(ClassScheduleDetailBean bean:allList)
//    		log.info("---"+bean);
    	initWeekSchedule(allList, week, moningNum, noonNum, afterNoonNum, nightNum);
    	initDaySchedule(allList, week, moningNum, noonNum, afterNoonNum, nightNum, dayForWeek) ;
	}
	
	
	private void initNoSetting(){
		List<ClassScheduleSettingsBean> setList = getScheduleSettingService().getSettings();
		int  moningNumber = 0,noonNumber = 0,afternoonNumber = 0 , nightNumber = 0;
		for(ClassScheduleSettingsBean b : setList){
			if(b.getClassScheduleType().equals(String.valueOf(Contants.SCHEDULE_TYPE_MORNING))){
				moningNumber = b.getNumber();
			}else if(b.getClassScheduleType().equals(String.valueOf(Contants.SCHEDULE_TYPE_FORENOON))){
				noonNumber = b.getNumber();
			}else if(b.getClassScheduleType().equals(String.valueOf(Contants.SCHEDULE_TYPE_AFTERNOON))){
				afternoonNumber = b.getNumber();
			}else if(b.getClassScheduleType().equals(String.valueOf(Contants.SCHEDULE_TYPE_NIGHT))){
				nightNumber = b.getNumber();
			}
		}
		
		StringBuffer weekBuf = new StringBuffer();
		weekBuf.append("<table class='table table-bordered table-striped tab-b'>");
		weekBuf.append("<thead>");
		weekBuf.append("<tr>");
		weekBuf.append("<th class='col-odd'>&nbsp;</th>");
		weekBuf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_MONDAY)+"</th>");
		weekBuf.append("<th class='col-even' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_TUESDAY)+"</th>");
		weekBuf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_WEDNESDAY)+"</th>");
		weekBuf.append("<th class='col-even' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_THURSDAY)+"</th>");
		weekBuf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_FRIDAY)+"</th>");
		weekBuf.append("<th class='col-even' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_SATURDAY)+"</th>");
		weekBuf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_SUNDAY)+"</th>");
		weekBuf.append("</tr>");
		weekBuf.append("</thead>");
		
		StringBuffer dayBuf = new StringBuffer();
		dayBuf.append("<table class='table table-bordered table-striped tab-b'>");
		
		//初始化早上的课程
		int count = moningNumber;
		for(int i=0; i<count; i++){
			weekBuf.append("<tr>");
			dayBuf.append("<tr>");
    		if(i==0){
    			if(count >1){
    				weekBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
    				dayBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
    			}else if(count == 1){
    				weekBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
    				dayBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
    			}
    		}
    		weekBuf.append(" <td   width='153px'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>");
    		dayBuf.append(" <td>&nbsp;</td>");
    		weekBuf.append(" </tr>");
    		dayBuf.append(" </tr>");
    	}
		
		//设置上午课程
		count = noonNumber;
		for(int i=0; i<count; i++){
			weekBuf.append("<tr>");
			dayBuf.append("<tr>");
    		if(i==0){
    			if(count >1){
    				weekBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
    				dayBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
    			}else if(count == 1){
    				weekBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
    				dayBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
    			}
    		}
    		weekBuf.append(" <td   width='153px'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>");
    		dayBuf.append(" <td>&nbsp;</td>");
    		weekBuf.append(" </tr>");
    		dayBuf.append(" </tr>");
    	}
		
		//设置下午课程
		count = afternoonNumber;
		for(int i=0; i<count; i++){
			weekBuf.append("<tr>");
			dayBuf.append("<tr>");
    		if(i==0){
    			if(count >1){
    				weekBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
    				dayBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
    			}else if(count == 1){
    				weekBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
    				dayBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
    			}
    		}
    		weekBuf.append(" <td   width='153px'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>");
    		dayBuf.append(" <td>&nbsp;</td>");
    		weekBuf.append(" </tr>");
    		dayBuf.append(" </tr>");
    	}
		
		//设置下午课程
		count = nightNumber;
		for(int i=0; i<count; i++){
			weekBuf.append("<tr>");
			dayBuf.append("<tr>");
    		if(i==0){
    			if(count >1){
    				weekBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
    				dayBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
    			}else if(count == 1){
    				weekBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
    				dayBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
    			}
    		}
    		weekBuf.append(" <td width='153px'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>");
    		dayBuf.append(" <td>&nbsp;</td>");
    		weekBuf.append(" </tr>");
    		dayBuf.append(" </tr>");
    	}
		weekBuf.append(" </table>");
		dayBuf.append(" </table>");
		
		weekSchedule = weekBuf.toString();
		daySchedule = dayBuf.toString();
		log.info(weekSchedule);
		log.info(daySchedule);
	}
	
	/**
	 * 初始化一周课程表
	 */
	private void initWeekSchedule(List<ClassScheduleDetailBean> allList,String[][] week,int moningNum ,int noonNum ,int afterNoonNum ,int nightNum ){
		StringBuffer buf = new StringBuffer();
    	buf.append("<table class='table table-bordered table-striped tab-b'>");
    	buf.append("<thead>");
    	buf.append("<tr>");
		buf.append("<th class='col-odd'>&nbsp;</th>");
		buf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_MONDAY)+"</th>");
		buf.append("<th class='col-even' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_TUESDAY)+"</th>");
		buf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_WEDNESDAY)+"</th>");
		buf.append("<th class='col-even' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_THURSDAY)+"</th>");
		buf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_FRIDAY)+"</th>");
		buf.append("<th class='col-even' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_SATURDAY)+"</th>");
		buf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_SUNDAY)+"</th>");
    	buf.append("</tr>");
    	buf.append("</thead>");
    	StringBuffer temp = null;
    	for(ClassScheduleDetailBean b:allList){
    		temp = new StringBuffer();
    		if(!Contants.SCHEDULE_CLASS_SUBJECT_INIT.equalsIgnoreCase(b.getSubjects())){
    			temp.append(b.getSubjects());
	    		temp.append("<br/>");
	    		temp.append("<i class='n14-icon-map-marker'></i>");
				temp.append(b.getClassAddress().length() > 8 ? b.getClassAddress().substring(0,8)+"..." : b.getClassAddress());
				temp.append("<br/>");
				temp.append(b.getStartTime());
				temp.append("-");
				temp.append(b.getEndTime());
				temp.append("<br/>");
				temp.append("<i class='n14-icon-calendar'></i>");
				temp.append(b.getStartWeek());
				temp.append("-");
				temp.append(b.getEndWeek());
				temp.append(getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_UNIT));
    		}else{
    			temp.append("<div style='min-width:80px;min-height:50px'/>");
    		}
    		week[b.getNumber()][b.getWeek()-1] = temp.toString();
    	}
    	
    	int line = 0;
    	//添加早上课程表
    	buf.append("<tr>");
    	if(moningNum > 1)
    		buf.append("<td rowspan='"+moningNum+"' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
    	else
    		buf.append("<td  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
    	buf.append("<td style='text-align:center' class='col2'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
    	buf.append("</tr>");
    	line++;
    	while(line<moningNum){
    		buf.append("<tr>");
//    		if(line % 2 == 0){
//    			buf.append("<td class='block-w'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
//    		}else{
    			buf.append("<td style='text-align:center' class='col2'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
//    		}
        	buf.append("</tr>");
        	line++;
    	}
    	
    	//添加上午课程表 
    	buf.append("<tr>");
    	if(noonNum > 1)
    		buf.append("<td rowspan='"+noonNum+"'  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
    	else
    		buf.append("<td  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
//    	if(line % 2 == 0){
			buf.append("<td style='text-align:center' class='col2'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
//		}else{
//			buf.append("<td class='block-b'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
//		}
    	buf.append("</tr>");
    	line++;
    	while(line<moningNum+noonNum){
    		buf.append("<tr>");
//    		if(line % 2 == 0){
    			buf.append("<td style='text-align:center' class='col2'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
//    		}else{
//    			buf.append("<td class='block-b'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
//    		}
        	buf.append("</tr>");
        	line++;
    	}
    	
    	
    	//添加下午课程表 
    	buf.append("<tr>");
    	if(afterNoonNum > 1)
    		buf.append("<td rowspan='"+afterNoonNum+"'  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
    	else
    		buf.append("<td  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
//    	if(line % 2 == 0){
			buf.append("<td style='text-align:center' class='col2'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
//		}else{
//			buf.append("<td class='block-b'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
//		}
    	buf.append("</tr>");
    	line++;
    	while(line<moningNum+noonNum+afterNoonNum){
    		buf.append("<tr>");
//    		if(line % 2 == 0){
    			buf.append("<td style='text-align:center' class='col2'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
//    		}else{
//    			buf.append("<td class='block-b'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
//    		}
        	buf.append("</tr>");
        	line++;
    	}
    	
    	//添加晚上课程表 
    	buf.append("<tr>");
    	if(nightNum > 1)
    		buf.append("<td rowspan='"+nightNum+"'  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
    	else
    		buf.append("<td  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
//    	if(line % 2 == 0){
			buf.append("<td style='text-align:center' class='col2'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
//		}else{
//			buf.append("<td class='block-b'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
//		}
    	buf.append("</tr>");
    	line++;
    	while(line<moningNum+noonNum+afterNoonNum+nightNum){
    		buf.append("<tr>");
//    		if(line % 2 == 0){
    			buf.append("<td style='text-align:center' class='col2'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
//    		}else{
//    			buf.append("<td class='block-b'>"+getString(week[line][0])+"</td><td>"+getString(week[line][1])+"</td><td>"+getString(week[line][2])+"</td><td>"+getString(week[line][3])+"</td><td>"+getString(week[line][4])+"</td><td>"+getString(week[line][5])+"</td><td>"+getString(week[line][6])+"</td>");
//    		}
        	buf.append("</tr>");
        	line++;
    	}
    	buf.append("</table>");
    	weekSchedule = buf.toString();
    	log.info(weekSchedule);
	}
	
	
	/**
	 * 初始化当天课程表
	 */
	private void initDaySchedule(List<ClassScheduleDetailBean> allList,String[][] week,int moningNum ,int noonNum ,int afterNoonNum ,int nightNum,int dayForWeek ){
		StringBuffer buf = new StringBuffer();
    	buf.append("<table class='table table-bordered table-striped tab-b'>");
    	StringBuffer temp = null;
    	for(ClassScheduleDetailBean b:allList){
    		temp = new StringBuffer();
    		if(!Contants.SCHEDULE_CLASS_SUBJECT_INIT.equalsIgnoreCase(b.getSubjects())){
    			temp.append(b.getSubjects());
	    		temp.append("</td><td>");
	    		temp.append("<i class='n14-icon-map-marker'></i>");
				temp.append(b.getClassAddress().length() > 8 ? b.getClassAddress().substring(0,8)+"..." : b.getClassAddress());
				temp.append("&nbsp;&nbsp;");
				temp.append(b.getStartTime());
				temp.append("-");
				temp.append(b.getEndTime());
				temp.append("&nbsp;&nbsp;");
				temp.append("<i class='n14-icon-calendar'></i>");
				temp.append(b.getStartWeek());
				temp.append("-");
				temp.append(b.getEndWeek());
				temp.append(getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_UNIT));
    		}else
    			temp.append("</td><td><div style='min-width:80px;min-height:20px'/>");
    		week[b.getNumber()][b.getWeek()-1] = temp.toString();
    	}
    	
    	int line = 0;
    	//添加早上课程表
    	buf.append("<tr>");
    	if(moningNum > 1)
    		buf.append("<td rowspan='"+moningNum+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
    	else
    		buf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
    	if(line % 2 == 0)
    		buf.append("<td class='block-w' width='153px'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
    	else
    		buf.append("<td class='block-b' width='153px'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
    	buf.append("</tr>");
    	line++;
    	while(line<moningNum){
    		buf.append("<tr>");
    		if(line % 2 == 0)
        		buf.append("<td class='block-w'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
        	else
        		buf.append("<td class='block-b'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
        	buf.append("</tr>");
        	line++;
    	}
    	
    	//添加上午课程表 
    	buf.append("<tr>");
    	if(noonNum > 1)
    		buf.append("<td rowspan='"+noonNum+"'  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
    	else
    		buf.append("<td  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
    	if(line % 2 == 0)
    		buf.append("<td class='block-w'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
    	else
    		buf.append("<td class='block-b'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
    	buf.append("</tr>");
    	line++;
    	while(line<moningNum+noonNum){
    		buf.append("<tr>");
    		if(line % 2 == 0)
        		buf.append("<td class='block-w'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
        	else
        		buf.append("<td class='block-b'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
        	buf.append("</tr>");
        	line++;
    	}
    	
    	
    	//添加下午课程表 
    	buf.append("<tr>");
    	if(afterNoonNum > 1)
    		buf.append("<td rowspan='"+afterNoonNum+"'  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
    	else
    		buf.append("<td  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
    	if(line % 2 == 0)
    		buf.append("<td class='block-w'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
    	else
    		buf.append("<td class='block-b'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
    	buf.append("</tr>");
    	line++;
    	while(line<moningNum+noonNum+afterNoonNum){
    		buf.append("<tr>");
    		if(line % 2 == 0)
        		buf.append("<td class='block-w'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
        	else
        		buf.append("<td class='block-b'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
        	buf.append("</tr>");
        	line++;
    	}
    	
    	//添加晚上课程表 
    	buf.append("<tr>");
    	if(nightNum > 1)
    		buf.append("<td  rowspan='"+nightNum+"'  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
    	else
    		buf.append("<td   style='text-align:center' >"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
    	if(line % 2 == 0)
    		buf.append("<td class='block-w'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
    	else
    		buf.append("<td class='block-b'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
    	buf.append("</tr>");
    	line++;
    	while(line<moningNum+noonNum+afterNoonNum+nightNum){
    		buf.append("<tr>");
    		if(line % 2 == 0)
        		buf.append("<td class='block-w'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
        	else
        		buf.append("<td class='block-b'>"+getStringDay(week[line][dayForWeek-1])+"</td>");
        	buf.append("</tr>");
        	line++;
    	}
    	buf.append("</table>");
    	daySchedule = buf.toString();
    	log.info(daySchedule);
	}
	
	private String getString(String week){
		return week == null ? "  &nbsp;"  : week;
	}
	
	private String getStringDay(String week){
		return week == null ?  " &nbsp;</td> <td>" : week;
	}
	
	
	

	public String getWeekSchedule() {
		return weekSchedule;
	}

	public void setWeekSchedule(String weekSchedule) {
		this.weekSchedule = weekSchedule;
	}

	public String getDaySchedule() {
		return daySchedule;
	}

	public void setDaySchedule(String daySchedule) {
		this.daySchedule = daySchedule;
	}
	 

	
	
}
